package com.lufei4.chestnut.view;

import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.ToastUtils;
import com.lufei4.chestnut.R;
import com.lufei4.chestnut.network.BaseMvpActivity;
import com.lufei4.chestnut.network.BaseObjectBean;
import com.lufei4.chestnut.network.LoginBean;
import com.lufei4.chestnut.network.MainContract;
import com.lufei4.chestnut.network.MainPresenter;

import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MainActivity extends BaseMvpActivity<MainPresenter> implements MainContract.View {


    @BindView(R.id.editTextTextPersonName)
    EditText editTextTextPersonName;
    @BindView(R.id.editTextTextPassword)
    EditText editTextTextPassword;
    @BindView(R.id.button)
    Button button;
    private static Handler handler;
    private String string;
    private StringBuilder stringBuilder;

    @Override
    public int getLayoutId() {
        return R.layout.activity_main;
    }

    @Override
    public void initView() {
        mPresenter = new MainPresenter();
        mPresenter.attachView(this);
        handler = new Handler() {
            @Override
            public void handleMessage(@NonNull Message msg) {
                super.handleMessage(msg);
                if (msg.what == 11) {
                    Bundle data = msg.getData();
                    ToastUtils.showShort(data.getString("data"));
                }
            }
        };
    }


    @Override
    public void onSuccess(BaseObjectBean<LoginBean> bean) {
        ToastUtils.showShort(bean.toString());
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void onError(Throwable throwable) {

    }


    @OnClick({R.id.editTextTextPassword, R.id.button})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.editTextTextPassword:
                Thread thread = new Thread() {
                    @Override
                    public void run() {
                        Message message = new Message();
                        message.what = 11;
                        Bundle bundle = new Bundle();
                        bundle.putString("data", "我是修改后的消息222222");
                        message.setData(bundle);
                        handler.sendMessage(message);
                    }
                };
                thread.start();
                break;
            case R.id.button:
                mPresenter.login("asjdkaskjdh", "2514561456");

                break;
        }
    }

}
